package com.dgut.usermodule.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
@Entity
@Table(name="t_user")
@DynamicUpdate(true)
@DynamicInsert(true)
public class User {
	private Long id;//
	private String userName;//
	private String password;
	private String phone;
	private String email;
	@DateTimeFormat(pattern="yyyy/MM/dd HH:mm:ss")
	private Date date;//
	private List<Permission> perms = new ArrayList<>();
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	@Column(nullable=false,unique=true)
	public String getUserName() {
		return userName;
	}
	@Column(nullable=false)
	public String getPassword() {
		return password;
	}
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	@JoinTable(name="t_user_perm")
	public List<Permission> getPerms() {
		return perms;
	}
	public String getPhone() {
		return phone;
	}
	public String getEmail() {
		return email;
	}
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	@Column(updatable=false)
	public Date getDate() {
		return date;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setPerms(List<Permission> perms) {
		this.perms = perms;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", userName=" + userName + ", password=" + password + ", phone=" + phone + ", email="
				+ email + ", date=" + date + ", perms=" + perms + "]";
	}
	
}
